/**********************************************************************************
**
** Copyright (C) 2009 Jostein Bratlie
** Contact: jostein.bratlie@gmail.com | http://bratlie.info | http://episteme.hin.no
**
** This file is part of GMQtExt, a GMlib and Qt extension library
**
** GMQtExt is free software: you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** GMQtExt is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public License
** along with GMQtExt.  If not, see <http://www.gnu.org/licenses/>.
**
**********************************************************************************/

#ifndef PROPERTYMANAGER_H
#define PROPERTYMANAGER_H

// Qt
#include <QtCore/QMap>

// Qt Solutions
#include <qtvariantproperty.h>
#include <qtpropertymanager.h>

// GMlib
#include <gmPoint>

namespace GMQtExt {

  class SurfacePlotPropertyManager : public QtAbstractPropertyManager {
    Q_OBJECT

  public:
    SurfacePlotPropertyManager( QObject* parent = 0x0 );
    ~SurfacePlotPropertyManager();

    GMlib::Point<int,2>         getNoDerivatives( const QtProperty* property ) const;
    GMlib::Point<int,2>         getNoSamples(const QtProperty *property) const;

    QtVariantPropertyManager*   getSubVariantPropertyManager();

  public slots:
    void                        setNoDerivatives( QtProperty*, const GMlib::Point<int,2>& );
    void                        setNoSamples(QtProperty *, const GMlib::Point<int,2> &);
    void                        slotForcedReplot();
  signals:
    void                        signForcedReplot();
    void                        valueChanged( QtProperty*, const GMlib::Point<int,2>&, const GMlib::Point<int,2>& );
  protected:
    QString                     valueText(const QtProperty *property) const;
    void                        initializeProperty(QtProperty *property);
    void                        uninitializeProperty(QtProperty *property);
  private:
    struct Data {
      GMlib::Point<int,2> no_derivatives;
      GMlib::Point<int,2> no_samples;
      QtVariantProperty  *der_u;
      QtVariantProperty  *der_v;
      QtVariantProperty  *samp_u;
      QtVariantProperty  *samp_v;
    };

    QMap<const QtProperty*, Data>         _property_to_data;
    QMap<const QtProperty*, QtProperty*>  _sampu_to_property;
    QMap<const QtProperty*, QtProperty*>  _sampv_to_property;
    QMap<const QtProperty*, QtProperty*>  _deru_to_property;
    QMap<const QtProperty*, QtProperty*>  _derv_to_property;

    QtVariantPropertyManager              *_pm;
  };

} // GMQtExt





#endif // PROPERTYMANAGER_H
